package com.wl.dzt.basic.service;

import com.wl.dzt.basic.entity.BasicDic;
import com.wl.dzt.basic.entity.BasicRoleModel;
import com.wl.dzt.sys.core.dao.DB;
import com.wl.dzt.sys.core.dao.select.Select;
import com.wl.dzt.sys.core.dao.select.term.Term;
import com.wl.dzt.sys.core.dao.tree.TreeNode;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;


/**
 * @author wl_code@163.com
 * @version 1.0
 * @date 2018/7/12/012
 * @description 权限管理服务层
 * 
 */
@Service
@Transactional
public class BasicPowerService {

	/**
	 * <b>查询权限类型</b>
	 * <p>
	 * 查询权限类型
	 * </p>
	 *
	 * @return
	 */
	public List<Map<String, Object>> listPowerDic() {
		List<BasicDic> dics = DB.list(Select.create(BasicDic.class).where(Term.eq("dicParent.dicValue", "roleType")));
		List<Map<String, Object>> data = new ArrayList<>();
		dics.forEach(dic -> {
			TreeNode node = new TreeNode();
			node.setText(dic.getDicKey());
			node.setId(dic.getId());
			data.add(node.getMap());
		});
		return data;
	}

	/**
	 * <b>获取角色模块</b>
	 * <p>
	 * 获取角色模块
	 * </p>
	 *
	 * @return
	 */
	public Set<String> getRoleModels(String roleId) {
		Set<String> set = new LinkedHashSet<>();
		List<BasicRoleModel> list = DB.list(Select.create(BasicRoleModel.class).fields("modelId.id")
				.where(Term.eq("roleId.id", roleId)));
		list.forEach(s -> set.add(s.getModelId().getId()));
		return set;
	}

}
